package com.blog.dao.impl;

import com.blog.dao.BaseDao;
import com.blog.dao.UsersDao;
import com.blog.pojo.Users;
import com.blog.utils.SqlIUtils;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Dao层接口的实现层
 */
public class UsersDaoImpl extends BaseDao implements UsersDao {

    @Override
    public Users login(String username, String password) {
        Users u=null;
        if(SqlIUtils.isSqlValid(username+" "+password)){
            return u;
        }
        try {
            String sql="select * from tb_users where username=? and password=?";
            Object[] parms={username,password};
            ResultSet resultSet = this.execQuery(sql, parms);
            if(resultSet.next()){
                int id = resultSet.getInt(1);
                String uname = resultSet.getString(2);
                String pwd = resultSet.getString(3);
                int sex = resultSet.getInt(4);
                String birthday = resultSet.getString(5);
                String phone = resultSet.getString(6);
                String address = resultSet.getString(7);
                int del = resultSet.getInt(8);
                //封装对象
                u=new Users(id,uname,pwd,sex,birthday,phone,address,del);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            this.closeConn(conn,resultSet,ps);
        }
        return u;
    }
}
